# -*- coding: utf-8 -*-
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from datetime import timedelta

from jms.ods.tms.yl_tms_distribution_effective import jms_ods__yl_tms_distribution_effective

jms_dim__dim_yl_tms_distribution_effective_base_dt = SparkSqlOperator(
    task_id='jms_dim__dim_yl_tms_distribution_effective_base_dt',
    pool_slots=1,
    sla=timedelta(hours=2),
    master='yarn',
    #execution_timeout=timedelta(hours=1)
    #excel平均时长:1分16秒
    execution_timeout = timedelta(minutes=30),
    email=['rabie.zhuang@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dim__dim_yl_tms_distribution_effective_base_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dim/tms/dim_yl_tms_distribution_effective_base_dt/execute.sql',
    executor_cores=2 ,
    executor_memory='2G' ,
    num_executors=2 ,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled' : 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 3 ,
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.sql.sources.partitionOverwriteMode' : 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '2G' ,
    },
    hiveconf={
        'hive.exec.dynamic.partition' : 'true',  # 动态分区
        'hive.exec.dynamic.partition.mode' : 'nonstrict',
        'hive.exec.max.dynamic.partitions' : 20,  # 每天生成 20 个分区
        'hive.exec.max.dynamic.partitions.pernode': 20,  # 每天生成 20 个分区
    },
)

jms_dim__dim_yl_tms_distribution_effective_base_dt << [
    jms_ods__yl_tms_distribution_effective
]


